﻿using SharpSoft.Data.DAOS;
using System;
using System.Collections.Generic;
using System.Text;

namespace SharpSoft.Data
{
    public class ConfigInDatabase : ConfigBase
    {
        private Config_DAO dal;
        public ConfigInDatabase(Database database)
        {
            dal = new Config_DAO(database, -1);
        }
        protected override void OnInit()
        {
            base.buffer = this.dal.GetAll();
        }

        protected override void OnLoadValue(string key)
        {
            var val = dal.GetValue(key);
            if (this.buffer.ContainsKey(key))
            {
                this.buffer[key] = val;
            }
            else
            {
                this.buffer.Add(key, val);
            }
        }

        protected override void OnSaveValue(string key, string value)
        {
            dal.SetValue(key, value);
        }
    }
}
